﻿Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.IO

Namespace DotNetNuke.Modules.ActiveForums.Controls
    <DefaultProperty("Text"), ToolboxData("<{0}:SubmitForm runat=server></{0}:SubmitForm>")> _
    Public Class SubmitForm
        Inherits TopicBase
#Region "EditorModes"
        Enum EditorModes
            NewTopic
            Reply
            ReplyWithBody
            Quote
            EditTopic
            EditReply
        End Enum
#End Region
#Region "Private Members"
        Private _Subject As String = String.Empty
        Private _topicSubject As String = String.Empty
        Private _Summary As String = String.Empty
        Private _Body As String = String.Empty
        Private _Template As String = String.Empty
        Private _EditorType As EditorTypes
        Private _forumInfo As Forum
        Private _PostButton As New DotNetNuke.Modules.ActiveForums.Controls.ImageButton
        Private _CancelButton As New DotNetNuke.Modules.ActiveForums.Controls.ImageButton
        Private _clientId As String
        Private _topicIcon As String
        Private _editorMode As EditorModes
        Private _locked As Boolean = False
        Private _checked As Boolean = False
        Private _pinned As Boolean = False
        Private _subscribed As Boolean = False
        Private _announceStart As Date = Nothing
        Private _announceEnd As Date = Nothing
        Private _tags As String
        Private _categories As String = String.Empty
        Private _pollQuestion As String
        Private _pollType As String
        Private _pollOptions As String
        Private _showModOptions As Boolean = False
        Private _statusId As Integer = -1
        Private _AuthorName As String = String.Empty
        Private _postbackScript As String = String.Empty
        Private _topicReviewTemplate As String = String.Empty
        Private _contentId As Integer = -1
        Private _authorId As Integer = -1
        Private _allowHTML As Boolean = False
        Private _requireCaptcha As Boolean = True
        Private _topicPriority As Integer = 0
        Dim canModEdit As Boolean = False
        Dim canModApprove As Boolean = False
        Dim canEdit As Boolean = False
        Dim canReply As Boolean = False
        Dim canCreate As Boolean = False
        Dim canAttach As Boolean = False
        Dim canTrust As Boolean = False
        Dim canLock As Boolean = False
        Dim canPin As Boolean = False
        Dim canAnnounce As Boolean = False
        Dim canSubscribe As Boolean = False

#End Region
#Region "Public Properties"
        Public Property Template() As String
            Get
                Return _Template
            End Get
            Set(ByVal value As String)
                _Template = value
            End Set
        End Property
        Public Property AuthorName() As String
            Get
                AuthorName = txtUsername.Text
            End Get
            Set(ByVal value As String)
                _AuthorName = value
                txtUsername.Text = value
            End Set
        End Property
        Public Property Subject() As String
            Get
                Subject = txtSubject.Text
            End Get
            Set(ByVal value As String)
                _Subject = value
                txtSubject.Text = value
            End Set
        End Property
        Public Property TopicSubject() As String
            Get
                Return _topicSubject
            End Get
            Set(ByVal value As String)
                _topicSubject = value
            End Set
        End Property
        Public Property Summary() As String
            Get
                Summary = txtSummary.Text
            End Get
            Set(ByVal value As String)
                _Summary = value
                txtSummary.Text = value
            End Set
        End Property
        Public Property Body() As String
            Get
                If plhEditor.Controls.Count > 0 Then
                    Select Case EditorType
                        'Case EditorTypes.ACTIVEEDITOR
                        '    Dim txtEditor As New ActiveEditorControls.ActiveEditor
                        '    txtEditor = CType(plhEditor.Controls.Item(0), ActiveEditorControls.ActiveEditor)
                        '    Body = txtEditor.Text
                        Case EditorTypes.HTMLEDITORPROVIDER
                            Body = DirectCast(plhEditor.FindControl("txtBody"), DotNetNuke.UI.UserControls.TextEditor).Text
                        Case EditorTypes.TEXTBOX
                            Body = CType(txtEditor, TextBox).Text
                    End Select
                Else
                    Return _Body
                End If
                'Return String.Empty
            End Get
            Set(ByVal value As String)
                _Body = value
                'txtBody.Text = value
            End Set
        End Property
        Public Property PostButton() As DotNetNuke.Modules.ActiveForums.Controls.ImageButton
            Get
                Return _PostButton
            End Get
            Set(ByVal value As DotNetNuke.Modules.ActiveForums.Controls.ImageButton)
                _PostButton = value
            End Set
        End Property
        Public Property CancelButton() As DotNetNuke.Modules.ActiveForums.Controls.ImageButton
            Get
                Return _CancelButton
            End Get
            Set(ByVal value As DotNetNuke.Modules.ActiveForums.Controls.ImageButton)
                _CancelButton = value
            End Set
        End Property
        Public Property EditorType() As EditorTypes
            Get
                Return _EditorType
            End Get
            Set(ByVal value As EditorTypes)
                _EditorType = value
            End Set
        End Property
        Public Property ForumInfo() As Forum
            Get
                Return _forumInfo
            End Get
            Set(ByVal value As Forum)
                _forumInfo = value
            End Set
        End Property
        'Public Property TopicInfo() As TopicInfo
        '    Get
        '        Return _topicInfo
        '    End Get
        '    Set(ByVal value As TopicInfo)
        '        _topicInfo = value
        '    End Set
        'End Property
        Public Property TopicIcon() As String
            Get
                If String.IsNullOrEmpty(afposticons.PostIcon) Then
                    TopicIcon = String.Empty
                Else
                    TopicIcon = afposticons.PostIcon
                End If

                'Return _topicIcon
            End Get
            Set(ByVal value As String)
                _topicIcon = value
                afposticons.PostIcon = value
            End Set
        End Property
        Public Property Locked() As Boolean
            Get
                Locked = chkLocked.Checked
            End Get
            Set(ByVal value As Boolean)
                _locked = value
                chkLocked.Checked = value
            End Set
        End Property
        Public Property Pinned() As Boolean
            Get
                Pinned = chkPinned.Checked
            End Get
            Set(ByVal value As Boolean)
                _pinned = value
                chkPinned.Checked = value
            End Set
        End Property
        Public Property Subscribe() As Boolean
            Get
                Subscribe = chkSubscribe.Checked
            End Get
            Set(ByVal value As Boolean)
                _subscribed = value
                chkSubscribe.Checked = value
            End Set
        End Property
        Public Property IsApproved() As Boolean
            Get
                IsApproved = chkApproved.Checked
            End Get
            Set(ByVal value As Boolean)
                _checked = value
                chkApproved.Checked = value
            End Set
        End Property
        Public Property IsAnnounce() As Boolean
            Get
                IsAnnounce = chkAnnounce.Checked
            End Get
            Set(ByVal value As Boolean)
                chkAnnounce.Checked = value
            End Set
        End Property
        Public Property TopicPriority() As Integer
            Get
                TopicPriority = Integer.Parse(txtTopicPriority.Text)
            End Get
            Set(ByVal value As Integer)
                txtTopicPriority.Text = value.ToString
                _topicPriority = value

            End Set
        End Property
        Public Property AnnounceStart() As Date
            Get
                If calStartDate.SelectedDate = "" And _announceStart = Nothing Then
                    Return Utilities.NullDate
                ElseIf Not String.IsNullOrEmpty(calStartDate.SelectedDate) Then
                    Return CDate(calStartDate.SelectedDate)
                Else
                    Return _announceStart
                End If

            End Get
            Set(ByVal value As Date)
                _announceStart = value
                calStartDate.SelectedDate = value.ToString
            End Set
        End Property
        Public Property AnnounceEnd() As Date
            Get
                If calEndDate.SelectedDate = "" And _announceEnd = Nothing Then
                    Return Utilities.NullDate
                ElseIf Not String.IsNullOrEmpty(calEndDate.SelectedDate) Then
                    Return CDate(calEndDate.SelectedDate)
                Else
                    Return _announceEnd
                End If
                

            End Get
            Set(ByVal value As Date)
                _announceEnd = value
                calEndDate.SelectedDate = CStr(value)
            End Set
        End Property
        Public ReadOnly Property EditorClientId() As String
            Get
                Return _clientId
            End Get
        End Property
        Public Property EditorMode() As EditorModes
            Get
                Return _editorMode
            End Get
            Set(ByVal value As EditorModes)
                _editorMode = value
            End Set
        End Property
        Public Property Tags() As String
            Get
                Return _tags

            End Get
            Set(ByVal value As String)
                _tags = value
                'tsTags.SelectedText = value
            End Set
        End Property
        Public Property Categories() As String
            Get
                Return _categories
            End Get
            Set(ByVal value As String)
                _categories = value
            End Set
        End Property

        Public Property PollQuestion() As String
            Get
                PollQuestion = afpolledit.PollQuestion
            End Get
            Set(ByVal value As String)
                _pollQuestion = value
                afpolledit.PollQuestion = value
            End Set
        End Property
        Public Property PollType() As String
            Get
                PollType = afpolledit.PollType
            End Get
            Set(ByVal value As String)
                _pollType = value
                afpolledit.PollType = value
            End Set
        End Property
        Public Property PollOptions() As String
            Get
                PollOptions = afpolledit.PollOptions
            End Get
            Set(ByVal value As String)
                _pollOptions = value
                afpolledit.PollOptions = value
            End Set
        End Property
        Public Property ShowModOptions() As Boolean
            Get
                Return _showModOptions
            End Get
            Set(ByVal value As Boolean)
                _showModOptions = value
            End Set
        End Property
        Public Property StatusId() As Integer
            Get
                StatusId = aftopicstatus.Status
            End Get
            Set(ByVal value As Integer)
                _statusId = value
                aftopicstatus.Status = value
            End Set
        End Property
        Public ReadOnly Property PostBackScript() As String
            Get
                Return _postbackScript
            End Get
        End Property
        Public Property ContentId() As Integer
            Get
                Return _contentId
            End Get
            Set(ByVal value As Integer)
                _contentId = value
            End Set
        End Property
        Public Property AuthorId() As Integer
            Get
                Return _authorId
            End Get
            Set(ByVal value As Integer)
                _authorId = value
            End Set
        End Property
        Public Property AllowHTML() As Boolean
            Get
                Return _allowHTML
            End Get
            Set(ByVal value As Boolean)
                _allowHTML = value
            End Set
        End Property
        Public Property RequireCaptcha() As Boolean
            Get
                Return _requireCaptcha
            End Get
            Set(ByVal value As Boolean)
                _requireCaptcha = value
            End Set
        End Property
        Public Property TopicProperties() As List(Of PropertiesInfo)
#End Region
#Region "Protected Controls"
        Protected txtSubject As New TextBox
        Protected txtSummary As New TextBox
        Protected lblSubject As New Label
        'Protected editorActiveEditor As ActiveEditorControls.ActiveEditor
        Protected editorTextBox As TextBox
        Protected editorDNN As DotNetNuke.UI.UserControls.TextEditor
        Protected WithEvents plhEditor As New PlaceHolder
        Protected WithEvents btnPost As New DotNetNuke.Modules.ActiveForums.Controls.ImageButton
        Protected WithEvents btnSubmit As New Button
        Protected WithEvents btnCancel As New DotNetNuke.Modules.ActiveForums.Controls.ImageButton
        Protected WithEvents btnPreview As New DotNetNuke.Modules.ActiveForums.Controls.ImageButton
        Protected WithEvents plhControl As New PlaceHolder
        Protected txtEditor As New TextBox
        Protected afposticons As New DotNetNuke.Modules.ActiveForums.af_posticonlist
        Protected afpolledit As New DotNetNuke.Modules.ActiveForums.af_polledit
        Protected aftopicstatus As New DotNetNuke.Modules.ActiveForums.af_topicstatus
        Protected chkLocked As New CheckBox
        Protected chkPinned As New CheckBox
        Protected chkSubscribe As New CheckBox
        Protected chkAnnounce As New CheckBox
        Protected chkApproved As New CheckBox
        Protected WithEvents reqSubject As New System.Web.UI.WebControls.RequiredFieldValidator
        Protected WithEvents reqCustomBody As New Label
        Protected calStartDate As New DotNetNuke.Modules.ActiveForums.Controls.DatePicker
        Protected calEndDate As New DotNetNuke.Modules.ActiveForums.Controls.DatePicker
        Protected WithEvents ctlUpload As New DotNetNuke.Modules.ActiveForums.af_uploader
        Protected WithEvents ctlAttach As New DotNetNuke.Modules.ActiveForums.Controls.af_attach

        Protected WithEvents plhUpload As PlaceHolder
        'Protected WithEvents tsTags As DotNetNuke.Modules.ActiveForums.Controls.TextSuggest
        Protected WithEvents plhTopicReview As New PlaceHolder
        Protected WithEvents txtTopicPriority As New TextBox
        'Support for Anonymous
        Protected txtUsername As New TextBox
        Protected WithEvents reqUsername As New System.Web.UI.WebControls.RequiredFieldValidator
        Protected WithEvents ctlCaptcha As New DotNetNuke.UI.WebControls.CaptchaControl
        Protected WithEvents reqCaptcha As New System.Web.UI.WebControls.RequiredFieldValidator

        Private BodyTemplate As String = String.Empty






#End Region

        ' Defines the Click event.
        '
        Public Event BubbleClick As EventHandler
        Protected Sub OnBubbleClick(ByVal e As EventArgs)
            RaiseEvent BubbleClick(Me, e)
        End Sub

        Private Function ParseForm(ByVal template As String) As String
            

            Dim hasOptions As Boolean = False
            template = "<%@ Register TagPrefix=""am"" Namespace=""DotNetNuke.Modules.ActiveForums.Controls"" Assembly=""DotNetNuke.Modules.ActiveForums"" %>" & template
            template = "<%@ register src=""~/DesktopModules/ActiveForums/controls/af_posticonlist.ascx"" tagprefix=""af"" tagname=""posticons"" %>" & template
            template = template.Replace("[AF:INPUT:SUBJECT]", "<asp:textbox id=""txtSubject"" cssclass=""aftextbox"" runat=""server"" />")
            template = template.Replace("[AF:REQ:SUBJECT]", "<asp:requiredfieldvalidator id=""reqSubject"" validationgroup=""afform"" ControlToValidate=""txtSubject"" runat=""server"" />")
            template = template.Replace("[AF:REQ:BODY]", "<asp:label id=""reqCustomBody"" visible=""false"" runat=""server"" />")
            If template.Contains("[AF:BODY:TEMPLATE]") Then
                BodyTemplate = TemplateUtils.GetTemplateSection(template, "[AF:BODY:TEMPLATE]", "[/AF:BODY:TEMPLATE]")
                BodyTemplate = BodyTemplate.Replace("[AF:BODY:TEMPLATE]", String.Empty)
                BodyTemplate = BodyTemplate.Replace("[/AF:BODY:TEMPLATE]", String.Empty)
                template = TemplateUtils.ReplaceSubSection(template, String.Empty, "[AF:BODY:TEMPLATE]", "[/AF:BODY:TEMPLATE]")
            End If
            If template.Contains("[TOOLBAR") Then
                Dim lit As New LiteralControl
                Dim sToolbar As Object = DataCache.CacheRetrieve("aftb" & ModuleId)
                If sToolbar Is Nothing Then
                    sToolbar = Utilities.GetFileContent(SettingKeys.TemplatePath & "ToolBar.txt")
                    sToolbar = Utilities.ParseToolBar(sToolbar.ToString, TabId, ModuleId, UserId, CurrentUserType)
                    DataCache.CacheStore("aftb" & ModuleId, sToolbar)
                End If
                lit.Text = sToolbar.ToString
                template = template.Replace("[TOOLBAR]", sToolbar.ToString)
            End If

            template = template.Replace("[AF:INPUT:SUMMARY]", "<asp:textbox id=""txtSummary"" runat=""server"" />")
            template = template.Replace("[AF:INPUT:BODY]", "<asp:placeholder id=""plhEditor"" runat=""server"" />")
            template = template.Replace("[AF:LABEL:SUBJECT]", "<asp:label id=""lblSubject"" runat=""server"" />")
            If Not Request.IsAuthenticated And (canCreate Or canReply) Then
                If template.Contains("[AF:UI:ANON]") Then
                    template = template.Replace("[AF:INPUT:USERNAME]", "<asp:textbox id=""txtUsername"" cssclass=""aftextbox"" runat=""server"" />")
                    template = template.Replace("[AF:REQ:USERNAME]", "<asp:requiredfieldvalidator id=""reqUsername"" validationgroup=""afform"" ControlToValidate=""txtUsername"" runat=""server"" />")
                    template = "<%@ Register TagPrefix=""dnn"" Assembly=""DotNetNuke"" Namespace=""DotNetNuke.UI.WebControls""%>" & template
                    template = template.Replace("[AF:INPUT:CAPTCHA]", "<dnn:captchacontrol  id=""ctlCaptcha"" captchawidth=""130"" captchaheight=""40"" cssclass=""Normal"" runat=""server"" errorstyle-cssclass=""NormalRed""  />")
                    If Not RequireCaptcha Then
                        template = template.Replace("[RESX:SecurityCode]:[AF:REQ:SECURITYCODE]", String.Empty)
                    End If
                    template = template.Replace("[AF:UI:ANON]", String.Empty)
                    template = template.Replace("[/AF:UI:ANON]", String.Empty)


                End If
            Else
                template = TemplateUtils.ReplaceSubSection(template, String.Empty, "[AF:UI:ANON]", "[/AF:UI:ANON]")
            End If

            If Not EditorMode = EditorModes.NewTopic Or Not EditorMode = EditorModes.EditTopic Then
                template = template.Replace("[AF:UI:SECTION:TOPICREVIEW]", "<table class=""afsection"" cellpadding=""0"" cellspacing=""0""><tr><td class=""afsectionhd"" style=""border-left:solid 1px #b3b3b3;"">[RESX:TopicReview]</td><td class=""afsectionhd"" align=""right"" style=""border-right:solid 1px #b3b3b3;""><img id=""imgSectionTopicReview"" src=""" & ImagePath & "/images/arrows_left.png"" border=""0"" class=""afarrow"" onclick=""aftoggleSection('TopicReview');"" /></td></tr><tr><td colspan=""2"" class=""afsectiondsp"" id=""sectionTopicReview"" style=""display:none;""><div class=""affieldsetnote"">[RESX:TopicReview:Note]</div>")
                _topicReviewTemplate = TemplateUtils.GetTemplateSection(template, "[AF:CONTROL:TOPICREVIEW]", "[/AF:CONTROL:TOPICREVIEW]")
                template = TemplateUtils.ReplaceSubSection(template, "<asp:placeholder id=""plhTopicReview"" runat=""server"" />", "[AF:CONTROL:TOPICREVIEW]", "[/AF:CONTROL:TOPICREVIEW]")
                template = template.Replace("[/AF:UI:SECTION:TOPICREVIEW]", "</td></tr></table>")
            End If
            If Permissions.HasPerm(ForumInfo.Security.Tag, ForumUser.UserRoles) Then
                template = template.Replace("[AF:UI:SECTION:TAGS]", "<table class=""afsection"" cellpadding=""0"" cellspacing=""0""><tr><td class=""afsectionhd"" style=""border-left:solid 1px #b3b3b3;"">[RESX:Tags]</td><td class=""afsectionhd"" align=""right"" style=""border-right:solid 1px #b3b3b3;""><img id=""imgSectionTags"" src=""" & ImagePath & "/images/arrows_left.png"" border=""0"" class=""afarrow"" onclick=""aftoggleSection('Tags');"" /></td></tr><tr><td colspan=""2"" class=""afsectiondsp"" id=""sectionTags"" style=""display:none;""><div class=""affieldsetnote"">[RESX:Tags:Note]</div>")
                template = template.Replace("[AF:UI:FIELDSET:TAGS]", "<fieldset class=""affieldset""><legend>[RESX:Tags]</legend><div class=""affieldsetnote"">[RESX:Tags:Note]</div>")
                Dim tc As New TokensController
                Dim sTagOut As String = tc.TokenGet("editor", "[AF:CONTROL:TAGS]")
                If String.IsNullOrEmpty(sTagOut) Then
                    'sTagOut = "<am:textsuggest id=""tsTags"" runat=""server"" DataTextField=""TagName"" DataValueField=""TagName"" CssResults=""aftsresults"" CssResultItems=""aftsresultsitems"" CssResultItemsSelected=""aftsresultsel""  CssClass=""aftagstxt"" Width=""99%"" />"
                    sTagOut = "<input type=""text"" id=""txtTags"" style=""width:98%;"" class=""NormalTextBox""  />"
                    'sTagOut &= "<script type=""text/javascript"">amaf_loadSuggest('txtTags', null, -1);</script>"
                End If
                sTagOut = sTagOut.Replace("[TAGS]", Tags)
                template = template.Replace("[AF:CONTROL:TAGS]", sTagOut)
                template = template.Replace("[/AF:UI:FIELDSET:TAGS]", "</fieldset>")
                template = template.Replace("[/AF:UI:SECTION:TAGS]", "</td></tr></table>")
            End If
            'Properties
            If (EditorMode = EditorModes.EditTopic Or EditorMode = EditorModes.NewTopic) And Not ForumInfo.Properties Is Nothing Then
                Dim pTemplate As String = TemplateUtils.GetTemplateSection(template, "[AF:PROPERTIES]", "[/AF:PROPERTIES]")
                Dim propList As String = String.Empty
                For Each p As PropertiesInfo In ForumInfo.Properties
                    Dim pValue As String = String.Empty
                    If Not TopicProperties Is Nothing AndAlso TopicProperties.Count > 0 Then
                        For Each tp As PropertiesInfo In TopicProperties
                            If tp.PropertyId = p.PropertyId Then
                                pValue = tp.DefaultValue
                            End If
                        Next
                    End If
                    Dim tmp As String = pTemplate

                    If p.IsRequired Then
                        tmp = tmp.Replace("[AF:PROPERTY:LABEL]", "<span class=""afprop-required"">[RESX:" & p.Name & "]</span>")
                        tmp = tmp.Replace("[AF:PROPERTY:REQUIRED]", "<span class=""afrequired""></span>")
                    Else
                        tmp = tmp.Replace("[AF:PROPERTY:LABEL]", "<span class=""afprop-normal"">[RESX:" & p.Name & "]</span>")
                        tmp = tmp.Replace("[AF:PROPERTY:REQUIRED]", String.Empty)
                    End If
                    If p.DataType = "text" Then
                        tmp = tmp.Replace("[AF:PROPERTY:CONTROL]", "<input type=""text"" id=""afprop-" & p.PropertyId.ToString & """ class=""NormalTextBox afprop-input"" name=""afprop-" & p.PropertyId & """ value=""" & pValue & """ />")
                    ElseIf p.DataType = "yesno" Then
                        Dim sYesSelected As String = String.Empty
                        Dim sNoSelected As String = " checked=""checked"""
                        If pValue.ToLowerInvariant = "yes" Then
                            sYesSelected = " checked=""checked"""
                            sNoSelected = String.Empty
                        End If
                        tmp = tmp.Replace("[AF:PROPERTY:CONTROL]", "[RESX:Yes]:<input type=""radio"" id=""afprop-" & p.PropertyId.ToString & "-yes"" groupname=""afprop-" & p.PropertyId.ToString & """ class=""NormalTextBox afprop-radio"" name=""afprop-" & p.PropertyId & """ value=""Yes"" " & sYesSelected & " /> [RESX:No]:<input type=""radio"" id=""afprop-" & p.PropertyId.ToString & "-no"" groupname=""afprop-" & p.PropertyId.ToString & """ class=""NormalTextBox afprop-radio"" name=""afprop-" & p.PropertyId & """ value=""No"" " & sNoSelected & " />")
                    ElseIf p.DataType.Contains("list") Then
                        Dim sList As String = String.Empty
                        Dim lists As New DotNetNuke.Common.Lists.ListController
                        If p.DataType.Contains("list|") Then
                            sList = "<select id=""afprop-" & p.PropertyId.ToString & """ class=""NormalTextBox afprop-select"" name=""afprop-" & p.PropertyId.ToString & """>"

                            Dim lName As String = p.DataType.Substring(p.DataType.IndexOf("|") + 1)
                            Dim lc As DotNetNuke.Common.Lists.ListEntryInfoCollection = lists.GetListEntryInfoCollection(lName, String.Empty)
                            For Each l As DotNetNuke.Common.Lists.ListEntryInfo In lc
                                If pValue = l.Value Then
                                    sList &= "<option value=""" & l.Value & """ selected=""selected"">" & l.Text & "</option>"
                                Else
                                    sList &= "<option value=""" & l.Value & """>" & l.Text & "</option>"
                                End If

                            Next
                            sList &= "</select>"
                        ElseIf p.DataType.Contains("list-multi|") Then
                            sList = "<div class=""afprop-chklist"">"
                            sList &= "<ul>"
                            Dim lName As String = p.DataType.Substring(p.DataType.IndexOf("|") + 1)
                            Dim lc As DotNetNuke.Common.Lists.ListEntryInfoCollection = lists.GetListEntryInfoCollection(lName, String.Empty)
                            Dim pValues() As String = Nothing
                            If Not String.IsNullOrEmpty(pValue) Then
                                pValues = pValue.Split(CChar(","))
                            End If
                            For Each l As DotNetNuke.Common.Lists.ListEntryInfo In lc
                                Dim isSelected As Boolean = False
                                If Not pValues Is Nothing Then
                                    For Each pv As String In pValues
                                        If pv = l.Value Then
                                            isSelected = True

                                        End If
                                    Next
                                End If
                                sList &= "<li>"
                                If isSelected Then
                                    sList &= "<input type=""checkbox""  name=""afprop-" & p.PropertyId.ToString & """ value=""" & l.Value & """ checked=""checked"" />"
                                Else
                                    sList &= "<input type=""checkbox""  name=""afprop-" & p.PropertyId.ToString & """ value=""" & l.Value & """ />"
                                End If
                                sList &= "<span>" & l.Text & "</span></li>"
                            Next
                            sList &= "</ul></div>"
                        End If

                        tmp = tmp.Replace("[AF:PROPERTY:CONTROL]", sList)
                    End If
                    propList &= tmp
                Next
                template = TemplateUtils.ReplaceSubSection(template, propList, "[AF:PROPERTIES]", "[/AF:PROPERTIES]")
            Else
                template = TemplateUtils.ReplaceSubSection(template, String.Empty, "[AF:PROPERTIES]", "[/AF:PROPERTIES]")
            End If
            If (EditorMode = EditorModes.EditTopic Or EditorMode = EditorModes.NewTopic) And Permissions.HasPerm(ForumInfo.Security.Categorize, ForumUser.UserRoles) Then
                template = template.Replace("[AF:UI:SECTION:CATEGORIES]", "<table class=""afsection"" cellpadding=""0"" cellspacing=""0""><tr><td class=""afsectionhd"" style=""border-left:solid 1px #b3b3b3;"">[RESX:Categories]</td><td class=""afsectionhd"" align=""right"" style=""border-right:solid 1px #b3b3b3;""><img id=""imgSectionCategories"" src=""" & ImagePath & "/images/arrows_left.png"" border=""0"" class=""afarrow"" onclick=""aftoggleSection('Categories');"" /></td></tr><tr><td colspan=""2"" class=""afsectiondsp"" id=""sectionCategories"" style=""display:none;""><div class=""affieldsetnote"">[RESX:Categories:Note]</div>")
                template = template.Replace("[AF:UI:FIELDSET:CATEGORIES]", "<fieldset class=""affieldset""><legend>[RESX:Categories]</legend><div class=""affieldsetnote"">[RESX:Categories:Note]</div>")
                Dim sCatOut As String = String.Empty
                Dim cc As New Controls.CategoriesList(PortalId, ModuleId, ForumInfo.ForumID, ForumInfo.ForumGroupId)
                If TopicId > 0 Then
                    cc.SelectedValues = Categories
                End If
                sCatOut = cc.RenderEdit()
                template = template.Replace("[AF:CONTROL:CATEGORIES]", sCatOut)
                template = template.Replace("[/AF:UI:FIELDSET:CATEGORIES]", "</fieldset>")
                template = template.Replace("[/AF:UI:SECTION:CATEGORIES]", "</td></tr></table>")
            End If
            If (EditorMode = EditorModes.EditTopic Or EditorMode = EditorModes.NewTopic) And Permissions.HasPerm(ForumInfo.Security.Poll, ForumUser.UserRoles) Then
                template = "<%@ register src=""~/DesktopModules/ActiveForums/controls/af_polledit.ascx"" tagprefix=""af"" tagname=""polledit"" %>" & template
                template = template.Replace("[AF:UI:SECTION:POLL]", "<table class=""afsection"" cellpadding=""0"" cellspacing=""0""><tr><td class=""afsectionhd"" style=""border-left:solid 1px #b3b3b3;"">[RESX:Polls]</td><td class=""afsectionhd"" align=""right"" style=""border-right:solid 1px #b3b3b3;""><img id=""imgSectionPoll"" src=""" & ImagePath & "/images/arrows_left.png"" border=""0"" class=""afarrow"" onclick=""aftoggleSection('Poll');"" /></td></tr><tr><td colspan=""2"" class=""afsectiondsp"" id=""sectionPoll"" style=""display:none;""><div class=""affieldsetnote"">[RESX:Poll:Note]</div>")
                template = template.Replace("[/AF:UI:SECTION:POLL]", "</td></tr></table>")
                template = template.Replace("[AF:UI:FIELDSET:POLL]", "<fieldset class=""affieldset""><legend>[RESX:Polls]</legend><div class=""affieldsetnote"">[RESX:Poll:Note]</div>")
                template = template.Replace("[AF:CONTROL:POLL]", "<af:polledit id=""afpolledit"" runat=""server"" />")
                template = template.Replace("[/AF:UI:FIELDSET:POLL]", "</fieldset>")
                template = template.Replace("[AF:CONTROLS:SECTIONTOGGLE]", "<img id=""imgSectionPoll"" src=""" & ImagePath & "/images/arrows_left.png"" border=""0"" class=""afarrow"" onclick=""aftoggleSection('Poll');"" />")
            Else
                template = TemplateUtils.ReplaceSubSection(template, String.Empty, "[AF:UI:FIELDSET:POLL]", "[/AF:UI:FIELDSET:POLL]")
                template = template.Replace("[AF:CONTROL:POLL]", String.Empty)
            End If
            If EditorMode = EditorModes.ReplyWithBody Then
                template = template.Replace("[AF:UI:MESSAGEREPLY]", String.Empty)
                template = template.Replace("[/AF:UI:MESSAGEREPLY]", String.Empty)
                template = template.Replace("[AF:LABEL:BODYREPLY]", Body)
            Else
                template = TemplateUtils.ReplaceSubSection(template, String.Empty, "[AF:UI:MESSAGEREPLY]", "[/AF:UI:MESSAGEREPLY]")
            End If

            If template.Contains("[AF:UI:FIELDSET:OPTIONS]") Then
                template = template.Replace("[AF:UI:FIELDSET:OPTIONS]", "<fieldset class=""affieldset""><legend>[RESX:AdditionalOptions]</legend>")
                template = template.Replace("[/AF:UI:FIELDSET:OPTIONS]", "</fieldset>")
            End If

            Dim sOptions As String = GetOptions()
            template = template.Replace("[AF:CONTROL:OPTIONS]", sOptions)
            If template.Contains("[AF:UI:SECTION:OPTIONS]") Then
                If sOptions = String.Empty Then
                    template = template.Replace("[AF:UI:SECTION:OPTIONS]", String.Empty)
                    template = template.Replace("[/AF:UI:SECTION:OPTIONS]", String.Empty)
                Else
                    template = template.Replace("[AF:UI:SECTION:OPTIONS]", "<table class=""afsection"" cellpadding=""0"" cellspacing=""0""><tr><td class=""afsectionhd"" style=""border-left:solid 1px #b3b3b3;"">[RESX:AdditionalOptions]</td><td class=""afsectionhd"" align=""right"" style=""border-right:solid 1px #b3b3b3;""><img id=""imgSectionOptions"" src=""" & ImagePath & "/images/arrows_left.png"" border=""0"" class=""afarrow"" onclick=""aftoggleSection('Options');"" /></td></tr><tr><td colspan=""2"" class=""afsectiondsp"" id=""sectionOptions"" style=""display:none;""><div class=""affieldsetnote"">[RESX:Options:Note]</div>")
                    template = template.Replace("[/AF:UI:SECTION:OPTIONS]", "</td></tr></table>")
                End If

            End If
            If template.Contains("[AF:CONTROL:STATUS]") Then
                If EditorMode = EditorModes.EditTopic Or EditorMode = EditorModes.NewTopic Then
                    template = "<%@ register src=""~/DesktopModules/ActiveForums/controls/af_topicstatus.ascx"" tagprefix=""af"" tagname=""topicstatus"" %>" & template
                    template = template.Replace("[AF:CONTROL:STATUS]", "<af:topicstatus id=""aftopicstatus"" AutoPostBack=""False"" ForumId=""" & ForumInfo.ForumID & """ runat=""server"" />")
                End If

            End If

            template = template.Replace("[AF:LINK:FORUMNAME]", "<a href=""" & NavigateUrl(TabId, "", ParamKeys.ViewType & "=" & Views.Topics & "&" & ParamKeys.ForumId & "=" & ForumInfo.ForumID.ToString) & """>" & ForumInfo.ForumName & "</a>")
            template = template.Replace("[AF:LINK:FORUMGROUP]", "<a href=""" & NavigateUrl(TabId, "", ParamKeys.GroupId & "=" & ForumInfo.ForumGroupId.ToString) & """>" & ForumInfo.GroupName & "</a>")
            template = template.Replace("[AF:LINK:FORUMMAIN]", "<a href=""" & NavigateUrl(TabId) & """>[RESX:FORUMS]</a>")
            If Not TopicId = -1 Then
                template = template.Replace("[AF:LINK:TOPICNAME]", "<a href=""" & NavigateUrl(TabId, "", ParamKeys.TopicId & "=" & TopicId & "&" & ParamKeys.ViewType & "=" & Views.Topic & "&" & ParamKeys.ForumId & "=" & ForumInfo.ForumID.ToString) & """>" & TopicSubject & "</a>")
            Else
                template = template.Replace("[AF:LINK:TOPICNAME]", String.Empty)
            End If
            template = template.Replace("[AF:UI:FIELDSET:ACTIONS]", "<fieldset class=""affieldset""><legend>[RESX:Actions]</legend>")
            template = template.Replace("[/AF:UI:FIELDSET:ACTIONS]", "</fieldset>")
            template = template.Replace("[AF:BUTTON:SUBMIT]", "<am:imagebutton id=""btnPost"" Text=""[RESX:Submit]"" runat=""server"" />")
            template = template.Replace("[AF:BUTTON:CANCEL]", "<am:imagebutton id=""btnCancel"" Text=""[RESX:Cancel]"" runat=""server"" />")
            If Request.IsAuthenticated Then
                template = template.Replace("[AF:BUTTON:PREVIEW]", "<am:imagebutton id=""btnPreview"" PostBack=""False""  Text=""[RESX:Preview]"" runat=""server"" />")
            Else
                template = template.Replace("[AF:BUTTON:PREVIEW]", String.Empty)
            End If

            If template.Contains("[AF:CONTROL:POSTICONS]") And ForumInfo.AllowPostIcon Then
                template = template.Replace("[AF:UI:FIELDSET:POSTICONS]", "<fieldset class=""affieldset""><legend>[RESX:PostIcons]</legend><div class=""affieldsetnote"">[RESX:PostIcons:Note]</div>")
                template = template.Replace("[AF:CONTROL:POSTICONS]", "<af:posticons id=""afposticons"" runat=""server"" Theme=""" & MainSettings.Theme & """ />")
                template = template.Replace("[/AF:UI:FIELDSET:POSTICONS]", "</fieldset>")

            Else
                template = template.Replace("[AF:UI:FIELDSET:POSTICONS]", String.Empty)
                template = template.Replace("[AF:CONTROL:POSTICONS]", String.Empty)
                template = template.Replace("[/AF:UI:FIELDSET:POSTICONS]", String.Empty)
            End If
            If template.Contains("[AF:CONTROL:EMOTICONS]") And ForumInfo.AllowEmoticons Then
                Dim objUtils As New emoticons
                'Dim obj As Object = DataCache.CacheRetrieve(ForumModuleId & "Emoticons" & EditorType.ToString)
                'If obj Is Nothing Then
                '    DataCache.CacheStore(ForumModuleId & "Emoticons" & EditorType.ToString) = objUtils.LoadEmoticons(EditorType, ForumModuleId, ImagePath)
                'End If
                template = template.Replace("[AF:CONTROL:EMOTICONS]", "<fieldset class=""affieldset""><legend>[RESX:Smilies]</legend>" & objUtils.LoadEmoticons(EditorType, ModuleId, ImagePath) & "</fieldset>")
            Else
                template = template.Replace("[AF:CONTROL:EMOTICONS]", String.Empty)
            End If
            If template.Contains("[AF:CONTROL:UPLOAD]") Then
                If canAttach And ForumInfo.AllowAttach Then
                    template = "<%@ register src=""~/DesktopModules/ActiveForums/controls/af_attach.ascx"" tagprefix=""af"" tagname=""attach"" %>" & template
                    template = template.Replace("[AF:UI:FIELDSET:ATTACH]", "<fieldset class=""affieldset""><legend>[RESX:Attachments]</legend><div class=""affieldsetnote"">[RESX:Attacments:Note]</div>")
                    template = template.Replace("[AF:UI:SECTION:ATTACH]", "<table class=""afsection"" cellpadding=""0"" cellspacing=""0""><tr><td class=""afsectionhd"" style=""border-left:solid 1px #b3b3b3;"">[RESX:Attachments]</td><td class=""afsectionhd"" align=""right"" style=""border-right:solid 1px #b3b3b3;""><img id=""imgSectionAttach"" src=""" & ImagePath & "/images/arrows_left.png"" border=""0"" class=""afarrow"" onclick=""aftoggleSection('Attach');"" /></td></tr><tr><td colspan=""2"" class=""afsectiondsp"" id=""sectionAttach"" style=""display:none;""><div class=""affieldsetnote"">[RESX:Attachments:Note]</div>")
                    template = template.Replace("[AF:CONTROL:UPLOAD]", "<af:attach id=""ctlAttach"" runat=""server"" />")
                    template = template.Replace("[/AF:UI:FIELDSET:ATTACH]", "</fieldset>")
                    template = template.Replace("[/AF:UI:SECTION:ATTACH]", "</td></tr></table>")
                Else
                    template = template.Replace("[AF:UI:FIELDSET:ATTACH]", String.Empty)
                    template = template.Replace("[AF:CONTROL:UPLOAD]", String.Empty)
                    template = template.Replace("[/AF:UI:FIELDSET:ATTACH]", String.Empty)
                    template = template.Replace("[AF:UI:SECTION:ATTACH]", String.Empty)
                    template = template.Replace("[/AF:UI:SECTION:ATTACH]", String.Empty)
                End If

            End If
            'If str.Contains("[AF:CONTROL:FORUMTREE]") Then
            '    str = str.Replace("[AF:CONTROL:FORUMTREE]", "<af:forumtree id=""ctlForumTree"" runat=""server"" showcheckboxes=""true"" ModuleId=""" & ModuleId & """ />")
            '    sHeader &= "<%@ register src=""~/DesktopModules/ActiveForums/controls/af_forumtree.ascx"" tagprefix=""af"" tagname=""forumtree"" %>"
            'End If
            template = Utilities.LocalizeControl(template)
            template = Utilities.StripTokens(template)
            Return template
        End Function
        Private Function GetOptions() As String
            Dim sb As New Text.StringBuilder
            Dim bHasOptions As Boolean = False
            sb.Append("<table cellpadding=""2"" cellspacing=""0"">")
            If ForumInfo.IsModerated And canModApprove And ShowModOptions = True Then
                sb.Append("<tr><td>[RESX:Approved]:</td>")
                sb.Append("<td><asp:checkbox id=""chkApproved"" Text=""[RESX:Approved:Note]"" TextAlign=""right"" cssclass=""afcheckbox"" runat=""server"" /></td></tr>")
                bHasOptions = True
            End If
            If (canLock Or canModEdit) And (EditorMode = EditorModes.NewTopic Or EditorMode = EditorModes.EditTopic) Then
                sb.Append("<tr><td>[RESX:Locked]:</td>")
                sb.Append("<td><asp:checkbox id=""chkLocked"" Text=""[RESX:Locked:Note]"" TextAlign=""right"" cssclass=""afcheckbox"" runat=""server"" /></td></tr>")
                bHasOptions = True
            End If
            If (canPin Or canModEdit) And (EditorMode = EditorModes.NewTopic Or EditorMode = EditorModes.EditTopic) Then
                sb.Append("<tr><td>[RESX:Pinned]:</td>")
                sb.Append("<td><asp:checkbox id=""chkPinned"" Text=""[RESX:Pinned:Note]"" TextAlign=""right"" cssclass=""afcheckbox"" runat=""server"" /></td></tr>")
                bHasOptions = True
            End If
            If canSubscribe Then
                sb.Append("<tr><td>[RESX:Subscribe]:</td>")
                sb.Append("<td><asp:checkbox id=""chkSubscribe"" Text=""[RESX:Subscribe:Note]"" TextAlign=""right"" cssclass=""afcheckbox"" runat=""server"" /></td></tr>")
                bHasOptions = True
            End If
            If (EditorMode = EditorModes.NewTopic Or EditorMode = EditorModes.EditTopic) And Permissions.HasPerm(ForumInfo.Security.Prioritize, ForumUser.UserRoles) Then
                sb.Append("<tr><td>[RESX:TopicPriority]:</td>")
                sb.Append("<td><asp:textbox id=""txtTopicPriority"" cssclass=""aftextbox"" width=""75"" onkeypress=""return onlyNumbers(event);"" runat=""server"" /></td></tr>")
                bHasOptions = True
            End If
            sb.Append("</table>")
            If bHasOptions = False Then
                sb = New StringBuilder
            End If
            If canAnnounce And (EditorMode = EditorModes.NewTopic Or EditorMode = EditorModes.EditTopic) Then
                sb.Append("<table cellpadding=""2"" cellspacing=""0"">")
                sb.Append("<tr><td valign=""top"" colspan=""3"">[RESX:Announce]:</td></tr><tr><td></td>")
                sb.Append("<td>[RESX:Announce:StartDate]:</td><td><am:datepicker id=""calStartDate"" runat=""server"" /></td></tr><tr><td></td><td>[RESX:Announce:EndDate]:</td><td><am:datepicker id=""calEndDate"" runat=""server"" /></td></tr>")
                sb.Append("</table>")
                bHasOptions = True
            End If
            If bHasOptions Then
                Return sb.ToString
            Else
                Return String.Empty
            End If

        End Function
        Private Sub LoadForm()
            Me.AppRelativeVirtualPath = "~/submitform.ascx"
            Dim ctl As New Control
            ctl.AppRelativeTemplateSourceDirectory = "~/"
            ctl.ID = "ctlTemp"
            ctl = Me.ParseControl(ParseForm(Template))
            Me.Controls.Add(ctl)
            While Not ctl.Controls.Count = 0
                Me.Controls.Add(ctl.Controls.Item(0))
            End While

            calStartDate.NullDate = Utilities.NullDate.ToString
            calEndDate.NullDate = Utilities.NullDate.ToString
            'calStartDate.DateFormat = MainSettings.DateFormatString
            'calEndDate.DateFormat = MainSettings.DateFormatString
            If Not AnnounceStart = Utilities.NullDate Then
                calStartDate.SelectedDate = AnnounceStart.ToString
            End If
            If Not AnnounceEnd = Utilities.NullDate Then
                calEndDate.SelectedDate = AnnounceEnd.ToString
            End If

            plhEditor = New PlaceHolder
            plhEditor = CType(Me.FindControl("plhEditor"), PlaceHolder)
            ''plhEditor.Controls.Clear()
            Dim editorWidth As Unit = 400
            Dim editorHeight As Unit = 400
            If Not CType(ForumInfo.EditorWidth, String) Is Nothing Then
                If InStr(CType(ForumInfo.EditorWidth, String), "%") > 0 Then
                    editorWidth = Unit.Percentage(CType(CType(ForumInfo.EditorWidth, String).TrimEnd(CType("%", Char)), Double))
                Else
                    editorWidth = Unit.Parse(ForumInfo.EditorWidth)
                End If
            Else
                editorWidth = Unit.Pixel(600)
            End If
            If Not CType(ForumInfo.EditorHeight, String) Is Nothing Then

                editorHeight = Unit.Parse(ForumInfo.EditorHeight)
            Else
                editorHeight = Unit.Pixel(400)
            End If
            Select Case EditorType
                Case EditorTypes.TEXTBOX
                    Dim txtEditor As New TextBox
                    txtEditor.ID = "txtBody"
                    txtEditor.Width = editorWidth
                    txtEditor.Height = editorHeight
                    txtEditor.TextMode = TextBoxMode.MultiLine
                    txtEditor.Rows = 4
                    plhEditor.Controls.Add(txtEditor)
                    _clientId = txtEditor.ClientID
                Case EditorTypes.HTMLEDITORPROVIDER
                    Dim txtEditor As New DotNetNuke.UI.UserControls.TextEditor
                    txtEditor = CType(LoadControl("~/controls/TextEditor.ascx"), DotNetNuke.UI.UserControls.TextEditor)
                    txtEditor.ID = "txtBody"
                    txtEditor.ChooseMode = False
                    txtEditor.DefaultMode = "R"
                    txtEditor.ChooseRender = False
                    txtEditor.Mode = "RICH"
                    txtEditor.Width = editorWidth
                    txtEditor.Height = editorHeight
                    plhEditor.Controls.Add(txtEditor)
                    _clientId = txtEditor.ClientID
               
            End Select
            plhTopicReview = New PlaceHolder
            plhTopicReview = CType(Me.FindControl("plhTopicReview"), PlaceHolder)
            If Not plhTopicReview Is Nothing Then
                Dim ctlTopicView As New TopicView
                ctlTopicView.ModuleConfiguration = Me.ModuleConfiguration
                ctlTopicView.TopicTemplate = _topicReviewTemplate
                ctlTopicView.OptPageSize = Integer.MaxValue
                ctlTopicView.OptDefaultSort = "DESC"
                ctlTopicView.ForumInfo = Me.ForumInfo
                plhTopicReview.Controls.Add(ctlTopicView)
            End If

        End Sub
        Public Sub btnPost_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPost.Click

            Dim captcha As DotNetNuke.UI.WebControls.CaptchaControl = CType(Me.FindControl("ctlCaptcha"), DotNetNuke.UI.WebControls.CaptchaControl)
            If Not captcha Is Nothing Then
                If Not captcha.IsValid And RequireCaptcha And Not Request.IsAuthenticated Then
                    Exit Sub
                End If
            End If


            Dim rd As RadioButtonList = CType(afposticons.FindControl("rblMessageIcons1"), RadioButtonList)
            Dim stat As DropDownList = CType(aftopicstatus.FindControl("drpStatus"), DropDownList)

            Dim pollQuest As TextBox = CType(afpolledit.FindControl("txtPollQuestion"), TextBox)
            Dim pType As RadioButtonList = CType(afpolledit.FindControl("rdPollType"), RadioButtonList)
            Dim pOpt As TextBox = CType(afpolledit.FindControl("txtPollOptions"), TextBox)
            If Not rd Is Nothing Then
                TopicIcon = rd.SelectedItem.Value
            End If
            If Not stat Is Nothing Then
                StatusId = CInt(stat.SelectedItem.Value)
            End If
            If Not pollQuest Is Nothing Then
                PollQuestion = pollQuest.Text
                PollType = pType.SelectedItem.Value
                PollOptions = pOpt.Text
            End If
            If Not String.IsNullOrEmpty(Body) Then
                Body = Body.Replace("&nbsp;", " ")
                Dim tmpBody As String = Utilities.StripHTMLTag(Body)
                If String.IsNullOrEmpty(tmpBody) Then
                    reqCustomBody.Visible = True
                End If
                If Body.Trim = String.Empty Then
                    reqCustomBody.Visible = True
                End If
            Else
                reqCustomBody.Visible = True
            End If
            If Not Request.IsAuthenticated And Utilities.InputIsValid(txtUsername.Text.Trim) = False Then
                reqUsername.Visible = True
            End If

            OnBubbleClick(e)
        End Sub
        Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
            Dim stringWriter As System.IO.StringWriter = New System.IO.StringWriter
            Dim htmlWriter As HtmlTextWriter = New HtmlTextWriter(stringWriter)
            MyBase.Render(htmlWriter)
            Dim html As String = stringWriter.ToString()
            html = Utilities.LocalizeControl(html)
            writer.Write(html)
        End Sub

        Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
            canModEdit = Permissions.HasPerm(ForumInfo.Security.ModEdit, ForumUser.UserRoles)
            canModApprove = Permissions.HasPerm(ForumInfo.Security.ModApprove, ForumUser.UserRoles)
            canEdit = Permissions.HasPerm(ForumInfo.Security.Edit, ForumUser.UserRoles)
            canReply = Permissions.HasPerm(ForumInfo.Security.Reply, ForumUser.UserRoles)
            canCreate = Permissions.HasPerm(ForumInfo.Security.Create, ForumUser.UserRoles)
            canAttach = Permissions.HasPerm(ForumInfo.Security.Attach, ForumUser.UserRoles)
            canTrust = Permissions.HasPerm(ForumInfo.Security.Trust, ForumUser.UserRoles)
            canLock = Permissions.HasPerm(ForumInfo.Security.Lock, ForumUser.UserRoles)
            canPin = Permissions.HasPerm(ForumInfo.Security.Pin, ForumUser.UserRoles)
            canAnnounce = Permissions.HasPerm(ForumInfo.Security.Announce, ForumUser.UserRoles)
            canSubscribe = Permissions.HasPerm(ForumInfo.Security.Subscribe, ForumUser.UserRoles)
        End Sub
        Private Sub SubmitForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            LoadForm()
            LinkControls(Controls)
            'If Not tsTags Is Nothing Then
            '    tsTags.Delimiter = ","
            '    tsTags.CharsTillLoad = 2
            '    tsTags.SelectedText = _tags
            '    tsTags.SelectedValue = _tags
            'End If

            txtSubject.CssClass = "aftextbox"
            Dim MyTheme As String = MainSettings.Theme
            Dim MyThemePath As String = Page.ResolveUrl("~/DesktopModules/ActiveForums/themes/" & MyTheme)
            txtSubject.MaxLength = 255
            txtSummary.MaxLength = 2000
            txtSubject.Text = _Subject
            txtSummary.Text = _Summary
            txtUsername.Text = _AuthorName
            lblSubject.Text = _Subject
            lblSubject.CssClass = "aftextbox"
            txtSummary.CssClass = "aftextbox"
            chkLocked.Checked = _locked
            chkPinned.Checked = _pinned
            chkApproved.Checked = _checked
            chkSubscribe.Checked = _subscribed
            txtTopicPriority.Text = _topicPriority.ToString
            If AnnounceEnd > Utilities.NullDate Then
                calEndDate.SelectedDate = _announceEnd.ToString
            End If
            If AnnounceStart > Utilities.NullDate Then
                calStartDate.SelectedDate = _announceStart.ToString
            End If
            btnPost.ImageLocation = PostButton.ImageLocation
            btnPost.ImageUrl = PostButton.ImageUrl
            btnPost.EnableClientValidation = False
            btnPost.ValidationGroup = "afform"
            btnPost.ClientSideScript = PostButton.ClientSideScript
            btnPost.Height = PostButton.Height
            btnPost.Width = PostButton.Width
            btnPost.PostBack = PostButton.PostBack
            btnPost.CssClass = "amimagebutton"

            btnCancel.ImageLocation = CancelButton.ImageLocation
            btnCancel.ImageUrl = CancelButton.ImageUrl
            btnCancel.PostBack = CancelButton.PostBack
            btnCancel.ClientSideScript = CancelButton.ClientSideScript
            btnCancel.Confirm = CancelButton.Confirm
            btnCancel.ConfirmMessage = CancelButton.ConfirmMessage
            btnCancel.Height = CancelButton.Height
            btnCancel.Width = CancelButton.Width
            btnCancel.CssClass = "amimagebutton"

            btnPreview.Height = PostButton.Height
            btnPreview.Width = PostButton.Width
            btnPreview.CssClass = "amimagebutton"

            afposticons.PostIcon = _topicIcon

            If Not aftopicstatus Is Nothing Then
                aftopicstatus.Status = _statusId
            End If

            afpolledit.PollQuestion = _pollQuestion
            afpolledit.PollType = _pollType
            afpolledit.PollOptions = _pollOptions
            afpolledit.ModuleConfiguration = Me.ModuleConfiguration
            afpolledit.ForumInfo = ForumInfo

            ctlUpload.ForumInfo = ForumInfo
            ctlUpload.ModuleConfiguration = Me.ModuleConfiguration
            ctlUpload.ForumId = ForumInfo.ForumID

            reqSubject.ErrorMessage = "<img src=""" & MyThemePath & "/images/warning.png"" align=""absmiddle"" />"
            reqSubject.EnableClientScript = False
            reqUsername.ErrorMessage = "<img src=""" & MyThemePath & "/images/warning.png"" align=""absmiddle"" />"
            reqUsername.EnableClientScript = False
            reqCustomBody.Text = "<img src=""" & MyThemePath & "/images/warning.png"" align=""absmiddle"" />"
            btnPreview.ImageUrl = MyThemePath & "/images/preview32.png"
            btnPreview.ClientSideScript = "togglePreview(this);"
            btnPreview.ObjectId = "ancPreview"
            btnPreview.ImageLocation = PostButton.ImageLocation
            btnPreview.Height = PostButton.Height
            btnPreview.CssClass = "amimagebutton"

            If EditorMode = EditorModes.NewTopic Or EditorMode = EditorModes.Reply Or EditorMode = EditorModes.ReplyWithBody Then
                _Body = BodyTemplate
            End If
            Select Case EditorType
                'Case EditorTypes.ACTIVEEDITOR
                '    Dim txtEditor As New ActiveEditorControls.ActiveEditor
                '    txtEditor = CType(plhEditor.Controls.Item(0), ActiveEditorControls.ActiveEditor)
                '    txtEditor.Text = _Body
                Case EditorTypes.HTMLEDITORPROVIDER
                    DirectCast(plhEditor.FindControl("txtBody"), DotNetNuke.UI.UserControls.TextEditor).Text = _Body
                Case EditorTypes.TEXTBOX
                    CType(txtEditor, TextBox).Text = _Body
            End Select


            EmotScript()
            insertHTMLScript()
            Dim sb As New StringBuilder
            sb.Append("function CheckBody(sender, args){")
            sb.Append("if (args.Value == ''){")
            sb.Append(" args.IsValid = false;")
            sb.Append(" return;};")
            sb.Append(" args.IsValid = true;};")
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType, "bodyval", sb.ToString, True)
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType, "ampost", "<script type=""text/javascript"">function amPostback(){" & Page.ClientScript.GetPostBackEventReference(btnPost, String.Empty) & "};</script>", False)
            '_postbackScript = 
        End Sub
        Private Sub LinkControls(ByVal ctrls As ControlCollection)
            For Each ctrl As Control In ctrls
                Select Case ctrl.ID
                    Case "txtSubject"
                        txtSubject = CType(ctrl, TextBox)
                    Case "txtUsername"
                        txtUsername = CType(ctrl, TextBox)
                    Case "lblSubject"
                        lblSubject = CType(ctrl, Label)
                    Case "txtSummary"
                        txtSummary = CType(ctrl, TextBox)
                    Case "btnPost"
                        btnPost = CType(ctrl, Modules.ActiveForums.Controls.ImageButton)
                    Case "btnCancel"
                        btnCancel = CType(ctrl, Modules.ActiveForums.Controls.ImageButton)
                    Case "plhEditor"
                        Select Case EditorType
                            'Case EditorTypes.ACTIVEEDITOR
                            '    Dim txtEditor As New ActiveEditorControls.ActiveEditor
                            '    txtEditor = CType(plhEditor.Controls.Item(0), ActiveEditorControls.ActiveEditor)
                            Case EditorTypes.HTMLEDITORPROVIDER
                                Dim txtEditor As New DotNetNuke.UI.UserControls.TextEditor
                                txtEditor = CType(plhEditor.Controls.Item(0), DotNetNuke.UI.UserControls.TextEditor)
                            Case EditorTypes.TEXTBOX
                                txtEditor = CType(plhEditor.Controls.Item(0), TextBox)
                        End Select
                    Case "afposticons"
                        afposticons = CType(ctrl, DotNetNuke.Modules.ActiveForums.af_posticonlist)
                    Case "aftopicstatus"
                        aftopicstatus = CType(ctrl, DotNetNuke.Modules.ActiveForums.af_topicstatus)
                    Case "chkLocked"
                        chkLocked = CType(ctrl, CheckBox)
                    Case "chkPinned"
                        chkPinned = CType(ctrl, CheckBox)
                    Case "chkSubscribe"
                        chkSubscribe = CType(ctrl, CheckBox)
                    Case "txtTopicPriority"
                        txtTopicPriority = CType(ctrl, TextBox)
                    Case "chkApproved"
                        chkApproved = CType(ctrl, CheckBox)
                    Case "reqSubject"
                        reqSubject = CType(ctrl, System.Web.UI.WebControls.RequiredFieldValidator)
                    Case "reqCustomBody"
                        reqCustomBody = CType(ctrl, Label)
                    Case "calStartDate"
                        calStartDate = CType(ctrl, DotNetNuke.Modules.ActiveForums.Controls.DatePicker)
                    Case "calEndDate"
                        calEndDate = CType(ctrl, DotNetNuke.Modules.ActiveForums.Controls.DatePicker)
                    Case "btnPreview"
                        btnPreview = CType(ctrl, DotNetNuke.Modules.ActiveForums.Controls.ImageButton)
                        'Case "tsTags"
                        '    tsTags = CType(ctrl, DotNetNuke.Modules.ActiveForums.Controls.TextSuggest)
                    Case "afpolledit"
                        afpolledit = CType(ctrl, DotNetNuke.Modules.ActiveForums.af_polledit)
                    Case "ctlUpload"
                        ctlUpload = CType(ctrl, DotNetNuke.Modules.ActiveForums.af_uploader)
                    Case "ctlAttach"
                        ctlAttach = CType(ctrl, DotNetNuke.Modules.ActiveForums.Controls.af_attach)
                        ctlAttach.ModuleConfiguration = Me.ModuleConfiguration
                        ctlAttach.ModuleId = ModuleId
                        ctlAttach.EditorType = ForumInfo.EditorType

                    Case "ctlCaptcha"
                        ctlCaptcha = CType(ctrl, DotNetNuke.UI.WebControls.CaptchaControl)
                        If RequireCaptcha And Not Request.IsAuthenticated Then
                            ctlCaptcha.Visible = True
                        Else
                            ctlCaptcha.Visible = False
                        End If
                End Select
                If ctrl.Controls.Count > 0 Then
                    LinkControls(ctrl.Controls)
                End If
            Next
        End Sub
        Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

        End Sub
        Private Sub insertHTMLScript()
            Dim sb As New Text.StringBuilder
           
            sb.Append("var afeditor = '" & _clientId & "';")
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType, "editorHTML", sb.ToString, True)
        End Sub

        Private Sub EmotScript()
            Dim sb As New Text.StringBuilder
           
            sb.Append("var afeditor = '" & _clientId & "';")
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType, "emot", sb.ToString, True)
        End Sub
    
       
    End Class
End Namespace